package roger;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.*;
import org.xml.sax.helpers.*;

public class BricoloHandler extends DefaultHandler {

	boolean startGarage;
	List<Garage> garages = new ArrayList<Garage>();

	/*public void startElement(String nameSpaceURI, String localName, String rawName, Attributes attributs) throws SAXException {
		if (localName.equals("garage")) {
			startGarage = true;
			garages.add(new Garage());
			System.out.println(localName);
		}

		for (int i = 0; i < attributs.getLength(); i++) {
            System.out.println("     - " +  attributs.getLocalName(i) + " = " + attributs.getValue(i));
		}
	}

	public void endElement(String nameSpaceURI, String localName, String rawName) throws SAXException {
		if (localName.equals("garage")) {
			startGarage = false;
		}
	}*/
	


	private Locator locator;

	public BricoloHandler() {
		super();
		// On definit le locator par defaut.
		locator = new LocatorImpl();
	}

	public void setDocumentLocator(Locator value) {
		locator =  value;
	}

	public void startDocument() throws SAXException {
		System.out.println("Debut de l'analyse du document");
		System.out.println("------------------------------");
	}

	public void endDocument() throws SAXException {
		System.out.println("------------------------------");
		System.out.println("Fin de l'analyse du document" );
	}

	public void startElement(String nameSpaceURI, String localName, String rawName, Attributes attributs) throws SAXException {
		System.out.println("Debut balise : " + localName);
		if (localName.equals("garage")) {
			startGarage = true;
			garages.add(new Garage());
		}
		if (localName.equals("garage")) {
			startGarage = true;
			garages.add(new Garage());
		}
	}

	public void endElement(String nameSpaceURI, String localName, String rawName) throws SAXException {
		System.out.print("Fin balise : " + localName);
		System.out.println();
		if (localName.equals("garage")) {
			startGarage = false;
		}
	}

	public void characters(char[] ch, int start, int end) throws SAXException {
		String res = new String(ch, start, end);
		if (!res.trim().equals("")) {
			System.out.println("\tAttributs de la balise : ");
			System.out.println("\t#PCDATA : " + new String(ch, start, end));
		}
	}
	
}
